<?php

include_once($_SERVER["DOCUMENT_ROOT"]. "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/album/inc.php");
$g_cgival = array();
$g_show = array();
$g_pro = array();


if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}

function check_cgi_pro()
{
	global $g_cgival, $g_show, $g_pro;
	cgi::both($g_cgival['t'],"t","json");
	$g_cgival['t'] = string::un_html($g_cgival['t']);

	cgi::both($g_cgival['callback'], "callback", "");
	$g_cgival['callback'] = string::un_html(string::un_script_code($g_cgival['callback']));
	
	
	cgi::both($g_cgival['mid'],"mid","");
	$g_cgival['mid'] = string::un_html($g_cgival['mid']);
	
}


function get_data()
{
	global $g_cgival, $g_show, $g_pro;
	
	
	$mblog_from_api = new mblog_from_api();
	$comment_data = $mblog_from_api->api_get_comment_by_mid($g_cgival['mid']);
	
	foreach($comment_data["data"]["result"] as $key => $value)
	{
		$comment_data["data"]["result"][$key]["time_format"] = TimeFormatter::timeFormat(strtotime($value["created_at"]));
	}
	$g_show["data"] = $comment_data["data"];
}

 
try
{
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "发布成功～";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();


function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;
	
	if ($g_cgival['t'] == "serialize")
	{
		echo serialize($g_show);
	}
	elseif ($g_cgival['t'] == "json")
	{
		echo output::json("json", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "jsonp")
	{
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
	elseif($g_cgival['t'] == "perl")
	{
		$string = php_to_perl::php_array_to_perl_hash($g_show);
		$string = mb_convert_encoding($string, "GBK", "UTF-8");
		echo $string;
	}
	elseif($g_cgival['t'] == "iframe")
	{
		header("location:{$g_cgival['link']}");
	}
	else
	{
		
		echo output::json("jsonp", $g_show, $g_cgival['callback']);
	}
}